var express = require("express");
var router = express.Router();
const connect = require("../public/javascripts/conn.js");

router.all("*", (req, res, next) => {
  res.setHeader("Access-Control-Allow-Origin", "*");
  next();
});

// 获取数据
var result = {};

// 分类页面路由设置
router.get("/", function (req, res, next) {
  // 获取banner表中的数据
  connect.query("select * from banner", (err, data) => {
    if (err) {
      console.log(err);
    } else {
      result.banner = data;
    }
  });
  // 获取nav表中的数据
  connect.query("select * from nav", (err, data) => {
    if (err) {
      console.log(err);
    } else {
      result.nav = data;
    }
  });
  res.render("classify.ejs", { result: result, title: "商品分类" });
});

module.exports = router;
